package com.yunbao.project.basedata.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunbao.core.respones.*;
import com.yunbao.project.basedata.entity.Account;
import com.yunbao.project.basedata.query.AccountQuery;
import com.yunbao.project.basedata.service.IAccountService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 账户 前端控制器
 * </p>
 *
 * @author 安能
 * @since 2019-09-16
 */
@RestController
@RequestMapping("account")
public class AccountController {


    @Resource
    IAccountService accountService;

    @PostMapping("insert")
    public Result insert(@RequestBody Account account) {
        accountService.save(account);
        return ResultBuilder.success(ResultEnum.ADD_SUCCESS);
    }

    @PostMapping("deleteById")
    public Result deleteById(Integer id) {

        accountService.removeById(id);
        return ResultBuilder.success(ResultEnum.DELETE_SUCCESS);
    }

    @PostMapping("updateById")
    public Result updateById(@RequestBody Account account) {

        accountService.updateById(account);
        return ResultBuilder.success(ResultEnum.UPDATA_SUCCESS);
    }

    @PostMapping("getById")
    public Account getById(Integer id) throws Exception {
        int i = 0 / 0;
//        throw new Exception("123");
     return   new Account().setName("安能");
//
//        Account account = accountService.getById(id);

//        return ResultBuilder.success(account);
    }

    /**
     * 获取账户列表
     *
     * @param accountQuery
     * @return 账户列表
     */
    @PostMapping("getList")
    public Result getList(@RequestBody AccountQuery accountQuery) {
        IPage<Account> page = accountService.page(new Page<>(
                        accountQuery.getCurrent(),
                        accountQuery.getSize()
                )
        );
        return ResultBuilder.success(page);
    }

    @PostMapping("getListLike")
    public Result getListLike(@RequestBody AccountQuery accountQuery) {

/*        IPage<account> listLike = accountService.getListLike(accountQuery);
        return ResultBuilder.success(listLike);*/
        return null;
    }
}
